import java.util.concurrent.locks.ReentrantLock;

public class Customer implements Runnable{
    private String name;
    private int money;
    private Seller seller;
    private static final ReentrantLock lock=new ReentrantLock(true);
    Customer(String name,int money,Seller seller){
        this.name=name;
        this.money=money;
        this.seller=seller;
    }
    private void buy(){
        lock.lock();
        if(seller.sellTicket(this.money)){
            this.money-=5;
            System.out.println(this.name);
            lock.unlock();
            Thread.currentThread().stop();
        }
        lock.unlock();
    }
    @Override
    public void run() {
        while(true){
            buy();
        }
    }
}